package org.guajava.controller.system;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.guajava.common.annotation.Log;
import org.guajava.common.base.AjaxResult;
import org.guajava.common.enums.BusinessType;
import org.guajava.domain.LoginInfor;
import org.guajava.domain.SysLogininfor;
import org.guajava.framework.web.base.BaseController;
import org.guajava.framework.web.page.TableDataInfo;
import org.guajava.service.ILoginInforService;

/**
 * 系统访问记录 前端控制器
 *
 * @author xieke
 * @email 949118693@qq.com
 * @date 2019-01-10 16:56:14
 */
@Controller
@RequestMapping("/system/logininfor")
public class SysLogininforController extends BaseController{

    private String prefix = "/system/logininfor";

    @Autowired
    private ILoginInforService loginInforService;

    @GetMapping()
    public String post() {
        return prefix + "/list";
    }

    @RequestMapping("/*")
    public void toHtml(){

    }

    @PostMapping("/listData")
    @ResponseBody
    public TableDataInfo listData(SysLogininfor loginInfor){
        startPage();
        List<SysLogininfor> list = loginInforService.selectLoginInforList(loginInfor);
        return getDataTable(list);
    }

    @Log(title = "系统访问记录添加", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public AjaxResult addSave(SysLogininfor loginInfor){
        return toAjax(loginInforService.insertLoginInfor(loginInfor));
    }


    @Log(title = "系统访问记录修改", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public AjaxResult editSave(SysLogininfor loginInfor) {
        return toAjax(loginInforService.updateLoginInfor(loginInfor));
    }

    @Log(title = "系统访问记录删除", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(loginInforService.deleteLoginInforByIds(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }
}
